package Wust_Java_Club_Middle_Test;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Eight_Queens_Puzzle {
	public static boolean[][] map;
	public static int[] col;
	public static int count=0,n;
	
	public static boolean judge(int row,int col) {
		for(int i=1;i<=row;i++) {
			if(map[i][col]) return false;
		}
		for(int i=row-1,j=col-1;i>=1&&j>=1;i--,j--) {
			if(map[i][j]) return false;
		}
		for(int i=row-1,j=col+1;i>=1&&j<=n;i--,j++) {
			if(map[i][j]) return false;
		}
		return true;
	}
	
	public static void dfs(int row) {
		if(row>n) {
			++count;
			if(count<=3) {
				for(int i =1;i<=n;i++) System.out.print(col[i]+" ");
				System.out.println();
			}
			return ;
		}
		
		for(int i=1;i<=n;i++) {
			if(judge(row, i)) {
				col[row]=i;
				map[row][i] = true;
				dfs(row+1);
				map[row][i]=false;
			}
		}
	}
	
	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		n=Integer.parseInt(in.readLine());
		map = new boolean[n+1][n+1];
		col = new int[n+1];
		dfs(1);
		System.out.println(count);
	}
}
